var details = {};
var page = 1;
var shopId ;
var perId;
$(document).ready(function () {

})
function getStaff() {
	$.ajax({
		type: 'get',
		url: baseUrl + 'hsent-xxyl-user/staffs/findBasicStaffsDetail',
		async: false,
		data: {
			shopId: shopId,
			staffsId: perId
		},
		success: function(res) {
			console.log(res)
			details.staff = res.data.basicStaffsBaseModel;
			details.list = res.data.shopAndGoodsModel.goodsList;
			details.picUrl = picUrl
			return details;
		}
	});
	return details;

}
//获取店铺信息
function getShop() {
	console.log(shopId)
	var shop;
	$.ajax({
		type: 'get',
		url: baseUrl + 'hsent-xxyl-user/store/showBasicInformation',
		async: false,
		data: {
			shopId: shopId
		},
		success: function(res) {
			details.shop = res.data
			console.log(details)
			return details;

		}
	})
	return details;

}
//获取店铺评论头部
function getCommentsTop() {
	console.log(shopId)

	var commentsTop;
	$.ajax({
		type: "get",
		url: baseUrl + 'hsent-xxyl-user/store/selectNums',
		async: false,
		data: {
			shopId: shopId
		},
		success: function(res) {

			details.commentsTop = res.data;
			return details;
		}
	});
	return details;

}
var str;
$('#staff').on('click', '.com-category span', function(e) {
	$(this).css({
		'background': 'rgb(35,106,173)',
		'color': '#fff'
	}).siblings().css({
		'background': '#fff',
		'color': 'rgb(16,16,16)'
	})
	str = e.target.innerHTML.split('(')[0]
	getComments(str, 1)

})
//获取更多评价
$('#staff').on('click', '.comments-more', function() {
    var that = $(this);
	page++;
	$.ajax({
		type: "get",
		url: baseUrl + 'hsent-xxyl-user/store/SelectAllEvaluation',
		async: false,
		data: {
			page: page,
			index: 3,
			status: '全部',
			shopId: '0600400007120190215'
		},
		success: function(res) {

			if(res.data.length > 0) {
				var arr = res.data
				var com = details.comments.concat(arr)
				details.comments = com;

				getData()

			} else {
			   that.html('无更多评价')
			   return;
			}

		}
	});

})
//获取用户评论
function getComments(state, page) {
	console.log(shopId)

	$.ajax({
		type: "get",
		url: baseUrl + 'hsent-xxyl-user/store/SelectAllEvaluation',
		async: false,
		data: {
			page: page,
			index: 3,
			status: state,
			shopId: shopId
		},
		success: function(res) {
			details.comments = res.data;
			getData()
		}
	});

}

var orderCon;

function getData() {
	orderCon = template('test', details);
	document.getElementById('staff').innerHTML = orderCon;
}

//getData('全部');
//基本信息
$(function() {
	var strli = getJumpData().split('&')
	perId = strli[0].split('=')[1]
	shopId = strli[1].split('=')[1]
	// var id = window.location.search.substr(4);
	getStaff(); //获取员工信息
	getShop(); //获取店铺信息
	getCommentsTop(); //获取评论头部
	getComments('全部', 1);
	getData();
	jump(goods,staff)

})

// function jump(goods, staff) {
// 	var href = 'itemDetail.html?'+'serverID='+goods.goodsId+'&pderid='+staff.shopId
// 	Tohref(href)
// 	console.log(goods);
// 	console.log(staff)
// }

